<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.SQLException"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
	Class.forName("com.mysql.jdbc.Driver");					
	Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/toursim", "root", "gaoxing311");
	
	//相对于添加,修改需要多收取id参数
	String id=request.getParameter("id");
	
	
	
	String name=request.getParameter("name");//null
	//避免下面解码时出现空指针异常
	name = (name==null?"":name);
	
	
	
	String price=request.getParameter("price");
	String intro=request.getParameter("intro");
	String proc=request.getParameter("proc");
	String city=request.getParameter("city");
	String addr=request.getParameter("addr");
	String img_intro=request.getParameter("img_intro");

	//修改中文参数的编码格式
	intro=new String(intro.getBytes("iso-8859-1"),"utf-8");
	proc=new String(proc.getBytes("iso-8859-1"),"utf-8");
	city=new String(city.getBytes("iso-8859-1"),"utf-8");
	addr=new String(addr.getBytes("iso-8859-1"),"utf-8");
	name=new String(name.getBytes("iso-8859-1"),"utf-8");

	//定义sql语句并执行
	String sql="update senior set name=?,price = ?,intro = ? ,proc= ?,city = ? ,addr = ?where id = ?";
	PreparedStatement ps=conn.prepareStatement(sql);
	ps.setString(1, name==null?"":name);
	ps.setString(3, intro==null?"":intro);
	ps.setString(4, proc==null?"":proc);
	ps.setString(5, city==null?"":city);
	ps.setString(6, addr==null?"":addr);
	//ps.setString(3, price==null?"":price);
	//ps.setString(1, id==null?"":id);
	ps.setDouble(2, Double.parseDouble(price)); 
	ps.setInt(7,Integer.parseInt(id));
	ps.execute();
	
	//重定向到列表页
	response.sendRedirect("page/index_main.jsp");
	

 %>
